//
//  ZLExamBeginExitPromptView.m
//  ZLExamination
//
//  Created by Zheng on 2017/8/23.
//  Copyright © 2017年 Zheng. All rights reserved.
//

#import "ZLExamBeginExitPromptView.h"

@implementation ZLExamBeginExitPromptView

- (void)showExitPromptView {
    self.hidden = NO;
    [UIView animateWithDuration:kANIMATION_DURATION animations:^{
        self.alpha = 1;
    } completion:^(BOOL finished) {
        
    }];
}

#pragma mark - 点击事件
- (void)cancelBtnClick:(UIButton *)sender {
    [UIView animateWithDuration:kANIMATION_DURATION animations:^{
        self.alpha = 0;
    } completion:^(BOOL finished) {
        self.hidden = YES;
    }];
}

- (void)enterBtnClick:(UIButton *)sender {
    
    [UIView animateWithDuration:kANIMATION_DURATION animations:^{
        self.alpha = 0;
    } completion:^(BOOL finished) {
        self.hidden = YES;
    }];
    _enterCallBack();
//    if (_enterCallBack) {
//        _enterCallBack();
//    }
}

#pragma mark - 初始化
- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [[UIColor grayColor] colorWithAlphaComponent:0.3];
        self.hidden = YES;
        self.alpha = 0;
        
        [self addSubview:self.whiteBgView];
        [_whiteBgView addSubview:self.titleLbl];
        [_whiteBgView addSubview:self.contentLbl];
        [_whiteBgView addSubview:self.cancelBtn];
        [_whiteBgView addSubview:self.enterBtn];
        [_whiteBgView addSubview:self.line1];
        [_whiteBgView addSubview:self.line2];
        
        [_whiteBgView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.equalTo(self).multipliedBy(0.87);
            make.height.mas_equalTo(kCX_Scale(170));
            make.centerX.centerY.equalTo(self);
        }];
        
        [_titleLbl mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(_whiteBgView);
            make.top.mas_equalTo(kCX_Scale(35));
        }];
        
        [_contentLbl mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(_whiteBgView);
            make.top.mas_equalTo(kCX_Scale(60));
        }];
        
        [_cancelBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.bottom.equalTo(_whiteBgView);
            make.height.mas_equalTo(kCX_Scale(55));
            make.width.mas_equalTo(kSCREEN_WIDTH/2-.25);
        }];
        
        [_enterBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.bottom.equalTo(_whiteBgView);
            make.height.mas_equalTo(kCX_Scale(55));
            make.width.mas_equalTo(kSCREEN_WIDTH/2-.25);
        }];
        
        [_line2 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.height.mas_equalTo(0.5);
            make.left.right.equalTo(_whiteBgView);
            make.bottom.mas_equalTo(-kCX_Scale(55));
        }];
        
        [_line1 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.mas_equalTo(0.5);
            make.top.equalTo(_line2.mas_bottom);
            make.height.mas_equalTo(kCX_Scale(55));
            make.centerX.equalTo(_whiteBgView);
        }];
        
    }
    return self;
}


#pragma mark - 子视图
- (UIView *)line1 {
    if (!_line1) {
        _line1 = [[UIView alloc] init];
        _line1.backgroundColor = [UIColor lightGrayColor];
    }
    return _line1;
}

- (UIView *)line2 {
    if (!_line2) {
        _line2 = [[UIView alloc] init];
        _line2.backgroundColor = [UIColor lightGrayColor];
    }
    return _line2;
}

- (UIView *)whiteBgView {
    if (!_whiteBgView) {
        _whiteBgView = [[UIView alloc] init];
        _whiteBgView.layer.backgroundColor = [[UIColor whiteColor] CGColor];
        _whiteBgView.layer.cornerRadius = 7;
        _whiteBgView.layer.masksToBounds = YES;
    }
    return _whiteBgView;
}

- (UILabel *)titleLbl {
    if (!_titleLbl) {
        _titleLbl = [[UILabel alloc] init];
        _titleLbl.font = kMyFont(15);
        _titleLbl.textAlignment = NSTextAlignmentCenter;
        _titleLbl.text = @"是否退出考试";
    }
    return _titleLbl;
}

- (UILabel *)contentLbl {
    if (!_contentLbl) {
        _contentLbl = [[UILabel alloc] init];
        _contentLbl.font = kMyFont(15);
        _contentLbl.textAlignment = NSTextAlignmentCenter;
        _contentLbl.text = @"退出考试后，将结束考试";
        _contentLbl.textColor = [UIColor darkGrayColor];
    }
    return _contentLbl;
}

- (UIButton *)cancelBtn {
    if (!_cancelBtn) {
        _cancelBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _cancelBtn.titleLabel.font = kMyFont(15);
        [_cancelBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [_cancelBtn setTitle:@"取消" forState:UIControlStateNormal];
        [_cancelBtn addTarget:self action:@selector(cancelBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _cancelBtn;
}

- (UIButton *)enterBtn {
    if (!_enterBtn) {
        _enterBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _enterBtn.titleLabel.font = kMyFont(15);
        [_enterBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [_enterBtn setTitle:@"确定" forState:UIControlStateNormal];
        [_enterBtn addTarget:self action:@selector(enterBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _enterBtn;
}


@end
